package pokerclient.core.network;

import pokerclient.core.ClientModel;
import common.GameState;
import common.Message;

/**
 * A protocol class which interprets messages, and delegates what needs to be
 * done to the right classes.
 */
public class ClientProtocol {

	private static ClientModel model = ClientModel.getInstance();

	/**
	 * This method processes incoming messages, and interprets them. As the
	 * request is on a "request and response" type, and it's the client that
	 * makes the requests, this method does not return a message.
	 * 
	 * @param message
	 *            the message to process
	 */
	public static void processMessage(Message message) {
		switch (message.getType()) {
		/*
		 * Case 1: The client has connected. In return, an empty message from
		 * the server, with type: 1. No needed action needed here, as the pinger
		 * take cares of updates.
		 */
		case 1:
			break;

		/*
		 * Case 2: The client has requested the game to start. The server
		 * answers with a Type: 2. No need to take any action, at least not with
		 * the current implementation (might be used for future features(tm)
		 * though)
		 */
		case 2:
			// We don't need to do anything, the next GameState will have all
			// the information we need., and the pinger handles that.
			break;

		/*
		 * Case 3: The client is receiving the complete GameState of the server.
		 * This contains all the information we need to update the view and keep
		 * the client in sync.
		 * 
		 * Pass the message on to the model, so it can process it.
		 */
		case 3:
			if (message.getValue() instanceof GameState) {
				GameState gameState = (GameState) message.getValue();
				model.processGameState(gameState);
			}
			break;
		}

	}
}
